import Util from '../../utils/imgsize';  
var app = getApp();
Page({

   /**
    * 页面的初始数据
    */
   data: {
      slideshow: false,
      sid: 0,
      info: {},
      imgs: '',
      userType: 1,
   },

   // 打开轮播遮罩层
   show: function (e) {
      var that = this;
      var id = e.target.dataset.id;
      that.setData({
         slideshow: true,
         imgs: id
      })
   },
   // 关闭遮罩层
   hide: function () {
      this.setData({
         slideshow: false
      })
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
      var sid = options.sid;
      var userType = app.api.userType;
      this.setData({
        sid: sid,
        userType: userType,
      });
   },

   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function () {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
      var that = this;
      var sid = that.data.sid;
      wx.request({
        url: app.api.hostUrl + '/Api/Supply/details',
        method: 'post',
        data: {
          sid: sid,
          uid: app.api.userId,
        },
        header: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          var status = res.data.status;
          if (status == 1) {
            var info = res.data.info;
            that.setData({
              info: info,
            });
          } else {
            wx.showToast({
              title: '没有找到相关信息.',
              duration: 2000
            });
          }
        },
        fail: function (e) {
          wx.showToast({
            title: '网络异常！',
            duration: 2000
          });
        },
      })
   },

   bindFormSubmit: function (e) {
     var that = this;
     var content = e.detail.value.cb;
     var userType = that.data.userType;
     if (userType!=2) {
       wx.showToast({
         title: '只有审核通过的认证医生才可以回复哦！',
         duration: 2000
       });
       return false;
     }
     if (!content) {
       wx.showToast({
         title: '您还没有输入内容！',
         duration: 2000
       });
       return false;
     }

     wx.request({
       url: app.api.hostUrl + '/Api/Supply/savedata',
       method: 'post',
       data: {
         sid: that.data.sid,
         content: content,
         uid: app.api.userId,
       },
       header: {
         'Content-Type': 'application/x-www-form-urlencoded'
       },
       success: function (res) {
         var status = res.data.status;
         if (status == 1) {
            wx.showToast({
              title: '发送成功.',
              duration: 2000
            });
            setTimeout(function(e){
              wx.navigateTo({
                url: '../article/article',
              })
            },2500);
         } else {
           wx.showToast({
             title: res.data.err,
             duration: 2000
           });
         }
       },
       fail: function (e) {
         wx.showToast({
           title: '网络异常！',
           duration: 2000
         });
       },
     })

   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide: function () {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload: function () {

   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage: function () {

   }
})